package mysql

import (
	"gorm.io/gorm"
	"rent-ease/rentrpc/rentrpc"
)

type Rent struct {
	gorm.Model
	RentName string `gorm:"type:varchar(10);comment:房名"`
	Address  string `gorm:"type:varchar(70);comment:地址"`
}

func (r *Rent) DetailRent(db *gorm.DB, id int64) error {
	return db.Debug().Where("id=?", id).First(r).Error
}

type User struct {
	gorm.Model
	Username string `gorm:"type:varchar(10);comment:用户名"`
	Password string `gorm:"type:varchar(32);comment:密码"`
}

func List(db *gorm.DB) []*rentrpc.List {
	var list []*rentrpc.List
	db.Debug().Model(&Rent{}).
		Select(
			"rents.id rent_id",
			"rent_name",
			"address",
		).Find(&list)
	return list
}
